﻿using UnityEngine;
using System.Collections;

public class TestMover : MonoBehaviour {
	private int moveX;
	private int moveY;
	private int tieBreaker;
	public float speed = 10f;
	private Transform enemyShip;
	public Transform playerShip;
	
	
	// Update is called once per frame
	void Start(){
		//set the transform data to enemyShip var
		enemyShip = transform;
		
		//Randomize x & y movement directions
		moveX = Random.Range (-1, 1);
		moveY = Random.Range (-1, 1);
		
		//Ensure the ship is always moving
		/*if (moveX == 0 && moveY == 0) {
			tieBreaker = Random.Range(0,3);
			if(tieBreaker == 0){
				moveX++;
			}
			if(tieBreaker == 1){
				moveX--;
			}
			if(tieBreaker == 2){
				moveY++;
			}
			if(tieBreaker == 3){
				moveY--;
			}
		}*/
	}
	
	void Update () {
		//Initiate movement direction
		transform.Translate (new Vector3 (moveX, 0, 0) * speed * Time.deltaTime);
		
		
		///Wrap enemy ship around screen on exit
		if(enemyShip.position.x >= 23)
		{
			enemyShip.position = new Vector3(-23, enemyShip.position.y, enemyShip.position.z);
		}
		else if(enemyShip.position.x <= -23)
		{
			enemyShip.position = new Vector3(23, enemyShip.position.y, enemyShip.position.z);
		}
		else if(enemyShip.position.y >= 11)
		{
			enemyShip.position = new Vector3(enemyShip.position.x,-11, enemyShip.position.z);
		}
		else if(enemyShip.position.y <= -11)
		{
			enemyShip.position = new Vector3(enemyShip.position.x,11, enemyShip.position.z);
		}
	}
}